package com.yx.pc.api.controller;

import com.yx.common.utils.PageUtils;
import com.yx.common.utils.Query;
import com.yx.common.utils.R;
import com.yx.modules.api.annotation.AuthIgnore;
import com.yx.system.entity.TdBook;
import com.yx.system.service.TdBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/*
* 比赛控制器
*/
@RequestMapping("/pc/api/game")
@RestController
public class PcTbGameController {

    @Autowired
    private TdBookService tdBookService;

    /*
    * 取得所有比赛图书并按照点击量排序
    */
    @RequestMapping("gamebooks")
    @AuthIgnore
    public R gamebooks(@RequestParam Map<String,Object> map){
        Query query = new Query(map);
        List<TdBook> tdBookList = tdBookService.queryGameList(query);
        int total = tdBookService.queryGameTotal(query);
        PageUtils pageUtil = new PageUtils(tdBookList, total, query.getLimit(), query.getPage());
        return R.ok().put("data", pageUtil);
    }

    /*
    * 获取点击榜单
    */
    @RequestMapping("gameCrunchiesClick")
    @AuthIgnore
    public R gameCrunchiesClick(@RequestParam Map<String,Object> map){
        Query query = new Query(map);
        query.put("gameClickCount","1");
        List<TdBook> tdBookList = tdBookService.queryGameCrunchiesList(query);
        int total = tdBookService.queryGameCrunchiesTotal(query);
        PageUtils pageUtil = new PageUtils(tdBookList, total, query.getLimit(), query.getPage());
        return R.ok().put("data", pageUtil);
    }

    /*
    * 获取订阅榜单
    */
    @RequestMapping("gameCrunchiesSubscribe")
    @AuthIgnore
    public R gameCrunchiesSubscribe(@RequestParam Map<String,Object> map){
        Query query = new Query(map);
        query.put("gameSubscribeCount","1");
        List<TdBook> tdBookList = tdBookService.queryGameCrunchiesList(query);
        int total = tdBookService.queryGameCrunchiesTotal(query);
        PageUtils pageUtil = new PageUtils(tdBookList, total, query.getLimit(), query.getPage());
        return R.ok().put("data", pageUtil);
    }
}
